import Vue from 'vue'
import store from '@/store'
import user from '@/store/modules/user'
// 全局自定义指令v-permission，判断当前用户是否用于该按钮权限
Vue.directive('permission', {
  inserted: async function(el,binding){
    let roles = store.getters.user && store.getters.user.roles
    console.log(user)
    if(!roles || roles.length==0){ //还没有获取roles
      let user = await store.dispatch('getUserInfo')
      roles = user.roles
    }
    if(!roles.includes(binding.value)){
      el.parentNode && el.parentNode.removeChild(el)
    }
  }
})